﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using System.Data.SqlClient;

namespace 共享单车管理系统
{
    public partial class Profrom : Form
    {
        public Profrom()
        {
            InitializeComponent();
        }

        SqlDataAdapter daEmployee, daProform;
        DataSet ds = new DataSet();

        void DispaiyChaat(string[] xlabeles, double[] yvalues,string serName)
        {
            chart1.Series.Clear();
            Series co1= new Series(serName);
            for (int i = 0; i < xlabeles.Length; i++)
            {
                DataPoint dp = new DataPoint(i, yvalues[i]);
                dp.AxisLabel = xlabeles[i];
                co1.Points.Add(dp);
            }
            chart1.Series.Add(co1);
            chart1.ChartAreas[0].AxisX.Interval = 1;
            chart1.Invalidate();
            
        }
        void init()
        {
            string str = @"SELECT e.EmployeeName AS ""员工姓名"", COUNT(o.orders) AS ""订单数"", SUM(CONVERT(decimal(10,2), o.proflit)) AS ""总利润""
                        FROM Employee e
                        INNER JOIN orders o ON e.EmployeeID = o.EmployeeID
                        WHERE o.Status = '已审核'
                        GROUP BY e.EmployeeName";

            string sdr = "SELECT * FROM Employee WHERE DepartmentID = 'D1004'";
            daProform = new SqlDataAdapter(str, DB.cn);
            daEmployee = new SqlDataAdapter(sdr, DB.cn);
            daProform.Fill(ds, "Proform_info");
            daEmployee.Fill(ds, "Employee_info");
        }

        private void Profrom_Load(object sender, EventArgs e)
        {
            init();
            showall();
            string[] XNAME=new string[ds.Tables["Proform_info"].Rows.Count];
            double[] Yprofit=new double[ds.Tables["Proform_info"].Rows.Count];
            for (int i = 0; i < ds.Tables["Proform_info"].Rows.Count; i++)
            {
                XNAME[i] = ds.Tables["Proform_info"].Rows[i][0].ToString();
                Yprofit[i]=double.Parse( ds.Tables["Proform_info"].Rows[i][2].ToString());
            }
            DispaiyChaat(XNAME, Yprofit,"员工业绩图");

        }

        void showall()
        {
            DataView dvProform = new DataView(ds.Tables["Proform_info"]);
            dgvPro.DataSource = dvProform;

            DataView dvEmployee = new DataView(ds.Tables["Employee_info"]);
            dgvEmp.DataSource = dvEmployee;
        }
    }
}